package cloud.zhixinglu.www.spring.boot.mybatis.controller;


import cloud.zhixinglu.www.spring.boot.mybatis.entity.TestEntity;
import cloud.zhixinglu.www.spring.boot.mybatis.mapper.TestMapper;
import cloud.zhixinglu.www.spring.boot.mybatis.pojo.dto.PageTestDTO;
import cloud.zhixinglu.www.spring.boot.mybatis.service.TestService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.page.PageMethod;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 *  控制层。
 *
 * @author WeiXin
 * @since 2023-08-12
 */
@RestController
@RequestMapping("/mybatis/")
public class TestController {

    @Resource
    private TestService testService;

    /**
     * 根据主键获取详细信息。
     *
     * @param operationId {@link String} 唯一操作ID
     * @return 详情
     */
    @GetMapping("getInfo/{operationId}")
    public TestEntity getInfo(@PathVariable String operationId) {
        TestEntity test = testService.getTestByOperationId(operationId);
        System.out.println(test);
        return test;
    }

    /**
     * 根据主键获取详细信息。
     *
     * @param id 主键
     * @return 详情
     */
    @GetMapping("getInfoList/{operationId}")
    public List<TestEntity> getInfoList(@PathVariable String operationId) {
        List<TestEntity> test = testService.getTestListByOperationId(operationId);
        System.out.println(test);
        return test;
    }

    /**
     * 查询所有。
     *
     * @return 所有数据
     */
    @GetMapping("getAllList")
    public List<TestEntity> getAllList() {
        return testService.selectListByLimit(100);
    }

    /**
     * 分页查询。
     *
     * @param page 分页对象
     * @return 分页对象
     */
    @GetMapping("pageTest")
    public Page<TestEntity> page(@RequestBody PageTestDTO pageTest) {
        Page<TestEntity> page = PageMethod.startPage(pageTest.getPageIndex(), pageTest.getPageSize());
        return testService.selectTestListByPage(page);
    }

}
